﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TourProject
{
    public partial class DSTour : DevExpress.XtraEditors.XtraForm
    {
        Connection con=new Connection();
        public DSTour()
        {
            InitializeComponent();
        }

        private void DSTour_Load(object sender, EventArgs e)
        {
            loadDiaDiem();

            loadTour();
            /*// TODO: This line of code loads data into the 'tourDBDataSet.Loai_Tour' table. You can move, or remove it, as needed.
            this.loai_TourTableAdapter.Fill(this.tourDBDataSet.Loai_Tour);
            // TODO: This line of code loads data into the 'tourDBDataSet.Gia_Tour' table. You can move, or remove it, as needed.
            this.gia_TourTableAdapter.Fill(this.tourDBDataSet.Gia_Tour);
            // TODO: This line of code loads data into the 'tourDBDataSet.DS_Dia_Diem' table. You can move, or remove it, as needed.
            this.dS_Dia_DiemTableAdapter.Fill(this.tourDBDataSet.DS_Dia_Diem);
            // TODO: This line of code loads data into the 'tourDBDataSet.Tour' table. You can move, or remove it, as needed.
            this.tourTableAdapter.Fill(this.tourDBDataSet.Tour);*/


        }
        private void loadTour()
        {
            DataTable da = new DataTable();
            con.KetNoi();
            da = con.select("select * from Tour");
            gridControl1.DataSource = da.DefaultView.Table;
        }
        private void loadDiaDiem()
        {
            DataTable da = new DataTable();
            //con = new Connection();
            con.KetNoi();
            da = con.select("select * from Dia_Diem");

            for (int i = 0; i < da.Rows.Count; i++)
            {
                listBoxControl1.Items.Add(da.Rows[i][2].ToString());
            }
            con.DongKetNoi();
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            gridView1.DeleteSelectedRows();
           
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            /*int index = listBoxControl1.SelectedIndex;
            if(index>= 0&& index<=listBoxControl1.Items.Count)
            {
                listBoxControl2.Items.Add(listBoxControl1.Items[index]);
                listBoxControl1.Items.RemoveAt(index);
            }*/
            quaLaiQuaLai(listBoxControl1, listBoxControl2);
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            /*int index = listBoxControl2.SelectedIndex;
            if (index >= 0 && index <= listBoxControl2.Items.Count)
            {
                listBoxControl1.Items.Add(listBoxControl2.Items[index]);
                listBoxControl2.Items.RemoveAt(index);
            }*/
            quaLaiQuaLai(listBoxControl2, listBoxControl1);
        }
        private void quaLaiQuaLai(ListBoxControl a, ListBoxControl b)
        {
            int index = a.SelectedIndex;
            if (index >= 0 && index <= a.Items.Count)
            {
                b.Items.Add(a.Items[index]);
                a.Items.RemoveAt(index);
            }
        }

        private void simpleButton5_Click(object sender, EventArgs e)
        {
            int index = listBoxControl2.SelectedIndex;
            if (index > 0 && index <= listBoxControl2.Items.Count)
            {
                string temp = listBoxControl2.Items[index - 1].ToString();
                listBoxControl2.SetItemValue(listBoxControl2.SelectedValue, index - 1);
                listBoxControl2.SetItemValue(temp, index);
                listBoxControl2.SelectedIndex = index-1;
            }
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            int index = listBoxControl2.SelectedIndex;
            if (index >= 0 && index < listBoxControl2.Items.Count-1)
            {
                string temp = listBoxControl2.Items[index + 1].ToString();
                listBoxControl2.SetItemValue(listBoxControl2.SelectedValue, index + 1);
                listBoxControl2.SetItemValue(temp, index);
                listBoxControl2.SelectedIndex = index + 1;
            }
        }

        private void simpleButton6_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            f.ShowDialog();
        }

        private void gridControl1_PaddingChanged(object sender, EventArgs e)
        {
         
        }


    }
}